package com.vhuomai.product.support;

import com.quanyue.auto.util.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author harris
 */
@Service
public class ProductDefaultEventEmiter implements ProductEventEmiter {
    
    @Autowired(required = false)
    private List<ProductEvent> productEvents;
    
    @Override
    public void emitUpdate(int productId) {
        if (CollectionUtils.isNotEmpty(productEvents)) {
            productEvents.forEach(productEvent -> productEvent.onUpdate(productId));
        }
    }
    
    @Override
    public void emitDelete(int productId) {
        if (CollectionUtils.isNotEmpty(productEvents)) {
            productEvents.forEach(productEvent -> productEvent.onDelete(productId));
        }
    }
}
